/**
 * @param {number[]} prices
 * @return {number}
 * 烦的
 */
var maxProfit = function(prices) {
    const n = prices.length;
    let maxprice = prices[n - 1];
    let result = 0;

    for (let i = n - 1; i >= 0; i--) {
        if (maxprice > prices[i]) {
            result = Math.max(result, maxprice - prices[i]);
        } else {
            maxprice = prices[i];
        }
    }

    return result;
};
